AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_spawnmenu.lua" )
AddCSLuaFile( "cl_notice.lua" )
AddCSLuaFile( "cl_hints.lua" )
AddCSLuaFile( "cl_worldtips.lua" )
AddCSLuaFile( "player_extension.lua" )
AddCSLuaFile( "cl_quicktool.lua" )

include( 'shared.lua' )
include( 'commands.lua' )
include( 'player.lua' )
include( 'rating.lua' )
include( 'player_extension.lua' )

/*---------------------------------------------------------
   Name: gamemode:PlayerSpawn( )
   Desc: Called when a player spawns
---------------------------------------------------------*/
function GM:PlayerSpawn( pl )

	self.BaseClass.PlayerSpawn( self, pl )
	
	// Set the player's speed
	GAMEMODE:SetPlayerSpeed( pl, 250, 500 )
	
end

/*---------------------------------------------------------
   Name: PlayerDataUpdate
---------------------------------------------------------*/
function PlayerDataUpdate( pl )

	if ( !pl ) then return end
	if ( !pl:IsValid() ) then return end
	
	
	pl:SetNetworkedString( "Website", 	pl:GetInfo( "cl_website" ) )
	pl:SetNetworkedString( "Location", 	pl:GetInfo( "cl_location" ) )
	pl:SetNetworkedString( "Email", 	pl:GetInfo( "cl_email" ) )
	pl:SetNetworkedString( "MSN", 		pl:GetInfo( "cl_msn" ) )
	pl:SetNetworkedString( "AIM", 		pl:GetInfo( "cl_aim" ) )
	pl:SetNetworkedString( "GTalk", 	pl:GetInfo( "cl_gtalk" ) )
	pl:SetNetworkedString( "XFire", 	pl:GetInfo( "cl_xfire" ) )
	
	timer.Simple( 1, PlayerDataUpdate, pl )

end

/*---------------------------------------------------------
   Name: gamemode:OnPhysgunFreeze( weapon, phys, ent, player )
   Desc: The physgun wants to freeze a prop
---------------------------------------------------------*/
function GM:OnPhysgunFreeze( weapon, phys, ent, ply )
	
	self.BaseClass:OnPhysgunFreeze( weapon, phys, ent, ply )

	ply:SendHint( "PhysgunUnfreeze", 0.3 )
	ply:SuppressHint( "PhysgunFreeze" )
	
end


/*---------------------------------------------------------
   Name: gamemode:OnPhysgunReload( weapon, player )
   Desc: The physgun wants to freeze a prop
---------------------------------------------------------*/
function GM:OnPhysgunReload( weapon, ply )

	local num = ply:PhysgunUnfreeze()
	
	if ( num > 0 ) then
		ply:SendLua( "GAMEMODE:UnfrozeObjects("..num..")" )
	end

	ply:SuppressHint( "PhysgunReload" )

end


/*---------------------------------------------------------
   Name: gamemode:PlayerShouldTakeDamage
   Return true if this player should take damage from this attacker
   Note: This is a shared function - the client will think they can 
	 damage the players even though they can't. This just means the 
	 prediction will show blood.
---------------------------------------------------------*/
function GM:PlayerShouldTakeDamage( ply, attacker )

	// The player should always take damage in single player..
	if ( SinglePlayer() ) then return true end

	// Global godmode, players can't be damaged in any way
	if ( server_settings.Bool( "sbox_godmode", false ) ) then return false end

	// No player vs player damage
	if ( attacker:IsValid() && attacker:IsPlayer() ) then
		return !server_settings.Bool( "sbox_plpldamage", false )
	end
	
	// Default, let the player be hurt
	return true

end


/*---------------------------------------------------------
   Called once on the player's first spawn
---------------------------------------------------------*/
function GM:PlayerInitialSpawn( ply )

	self.BaseClass:PlayerInitialSpawn( ply )
	
	PlayerDataUpdate( ply )
	
end


/*---------------------------------------------------------
   Desc: A ragdoll of an entity has been created
---------------------------------------------------------*/
function GM:CreateEntityRagdoll( entity, ragdoll )

	// Replace the entity with the ragdoll in cleanups etc
	undo.ReplaceEntity( entity, ragdoll )
	cleanup.ReplaceEntity( entity, ragdoll )
	
end


/*---------------------------------------------------------
   Name: gamemode:PlayerUnfrozeObject( )
---------------------------------------------------------*/
function GM:PlayerUnfrozeObject( ply, entity, physobject )

	local effectdata = EffectData()
		effectdata:SetOrigin( physobject:GetPos() )
	util.Effect( "phys_unfreeze", effectdata, true, true )	
	
end


/*---------------------------------------------------------
   Name: gamemode:PlayerFrozeObject( )
---------------------------------------------------------*/
function GM:PlayerFrozeObject( ply, entity, physobject )

	local effectdata = EffectData()
		effectdata:SetOrigin( physobject:GetPos() )
	util.Effect( "phys_freeze", effectdata, true, true )	
	
end